package com.firefly.web.configure;

import com.firefly.web.controller.admin.ConsoleApiRestController;
import com.firefly.web.controller.api.ApiRestController;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    /**
     * 请求路径添加统一前缀
     *
     * @param configurer
     */
    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        configurer.addPathPrefix("/api/", c -> c.isAnnotationPresent(ApiRestController.class))
                .addPathPrefix("/c-api/", c -> c.isAnnotationPresent(ConsoleApiRestController.class));
    }

    // 全局允许跨域
    /*@Override
    public void addCorsMappings(CorsRegistry registry){
        registry.addMapping("/**")
                //是否发送Cookie
                .allowCredentials(true)
                //放行哪些原始域
                .allowedOriginPatterns("*")
                .allowedMethods(new String[]{"GET", "POST", "PUT", "DELETE"})
                .allowedHeaders("*")
                .exposedHeaders("*");
    }*/
}
